<template>
    <!-- 两链管理-入口页 -->
    <div class="two-chains-manage">
        <div class="chains-left" v-if="twoChains">
            <ul>
                <li v-for="item in twoChains.yAxis" :key="item.name">
                    <div class="item-box primary">{{ item.name }}</div>
                </li>
            </ul>
        </div>
        <div class="chains-right" v-if="twoChains">
            <ul class="right-nav">
                <li v-for="(item, index) in twoChains.xAxis" :key="item.name">
                    <div :class="`item-box ${buttonTypes[index]}`">{{item.name}}</div>
                </li>
            </ul>
            <div>
                <ul v-for="(itemY, y) in twoChains.yAxis" :key="y">
                    <li v-for="(itemX, x) in twoChains.xAxis" :key="x">
                        <div class="target-box">
                            <div v-if="chainFile.length" v-html="fmtFile(itemX.code, itemY.code)"></div>
                            <div class="dot" @click="jumpList(itemX.code, itemY.code)"><i class="el-icon-more"></i></div>
                        </div>
                    </li>
                </ul>
            </div>
        </div>
    </div>
</template>

<script>
    import { mapGetters } from 'vuex'
    // 引入方法
    import { queryAllGroup } from '@/api/target';

    export default {
        name: 'twoChains',
        data () {
            return {
                buttonTypes: ['other', 'success', 'warning', 'danger', 'info', 'primary'],
                chainFile: []
            }
        },
        computed: {
            ...mapGetters(['systemInfo']),
            twoChains () {
                return this.$store.getters.twoChains
            }
        },
        async created () {
            await this.getChains()
        },
        methods: {
            // 跳转进入两链管理列表页
            jumpList (indexX, indexY) {
                this.$router.push({
                    path: '/target/chainsList',
                    query: {
                        indexX: indexX,
                        indexY: indexY
                    }
                })
            },
            // 获取两链管理所有文件
            getChains () {
                queryAllGroup().then(res => {
                    this.chainFile = res || [];
                }).catch()
            },
            fmtFile (itemX, itemY) {
                // 判断是否有X轴数据（学校层...）
                const fileX = this.chainFile;
                if (fileX.length) {
                    for (let i = 0; i < fileX.length; i++) {
                        // 判断是否Y轴数据（决策指挥...）
                        const yList = fileX[i].indexYList;
                        if (fileX[i].indexX === itemX && yList.length) {
                            for (let j = 0; j < yList.length; j++) {
                                if (yList[j].indexY === itemY) {
                                    // 判断XY轴是否有数据
                                    const fileY = yList[j].chainFileInfoDTOList;
                                    if (fileY.length) {
                                        let tempHtml = '';
                                        for (let k = 0; k < fileY.length; k++) {
                                            if (k < 4) {
                                                tempHtml += `<p class="ellipsis">${fileY[k].fileName}</p>`
                                            }
                                            if (k > 4) {
                                                tempHtml += '<p class="ellipsis">...</p>'
                                            }
                                        }
                                        return tempHtml;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
</script>

<style lang="scss" scoped>
@import "~@/assets/css/common.scss";

    .two-chains-manage {
        display: flex;
        padding-bottom: 40px;
        .item-box {
            width: 120px;
            height: 44px;
            line-height: 44px;
            text-align: center;
            border-radius: 30px;
            font-size: 14px;
            color: #6B6B6B;
            position: relative;
            &:after {
                content: '';
                position: absolute;
                width: 0;
                height: 0;
                bottom: -30px;
                left: 0;
                right: 0;
                margin: 0 auto;
                border-top: 12px solid #7FCDFF;
                border-right: 16px solid transparent;
                border-bottom: 16px solid transparent;
                border-left: 16px solid transparent;
            }

            &.primary {
                border-radius: 6px;
                background-color: #EAEDFB;
                border: 2px solid #0099CC;
                &:after {
                    right: -140px;
                    bottom: 7px;
                    border-top: 12px solid transparent;
                    border-right: 16px solid transparent;
                    border-bottom: 16px solid transparent;
                    border-left: 16px solid #0099CC;
                }
            }
            &.success {
                background-color: #F2FFF5;
                border: 2px solid #3BBE00;
                &:after {
                    border-top: 12px solid #3BBE00;
                }
            }
            &.info {
                background-color: #F2FFF5;
                border: 2px solid #7FCDFF;
                &:after {
                    border-top: 12px solid #7FCDFF;
                }
            }
            &.warning {
                background-color: #FFDFFF;
                border: 2px solid #FFBC41;
                &:after {
                    border-top: 12px solid #FFBC41;
                }
            }
            &.danger {
                background-color: #FFDFFF;
                border: 2px solid #FF1580;
                &:after {
                    border-top: 12px solid #FF1580;
                }
            }
            &.other {
                background-color: #FBF4FF;
                border: 2px solid #E19BFF;
                &:after {
                    border-top: 12px solid #E19BFF;
                }
            }
        }

        .chains-left {
            width: 130px;
            padding-top: 80px;

            li {
                margin: 10px;
                height: 150px;
                display: flex;
                align-items: center;
            }
        }
        .chains-right {
            width: calc(100% - 130px);
            .right-nav {
                height: 80px;
            }
            ul {
                display: flex;
                justify-content: space-around;
                li {
                    width: 18%;
                    margin: 10px;
                    box-sizing: border-box;
                    display: flex;
                    justify-content: center;
                    align-items: center;
                }
            }
        }
        .target-box {
            width: 100%;
            height: 140px;
            padding: 15px 25px 15px 15px;
            border-radius: 4px;
            box-sizing: border-box;
            background: $redLight;
            text-align: left;
            line-height: 24px;
            position: relative;
            p {
                overflow: hidden;
                text-overflow: ellipsis;
                white-space: nowrap;
            }
            .dot {
                position: absolute;
                right: 0;
                top: 0;
                width: 30px;
                height: 20px;
                background: #2A9EF7;
                color: $white;
                font-weight: bold;
                font-size: 20px;
                text-align: center;
                line-height: 16px;
                border-radius: 4px;
                cursor: pointer;
                &:hover{
                    background: #3d72ff;
                }
            }
        }
    }
</style>
